import matplotlib.pyplot as plt

# plt.style.use(['science','no-latex'])
# plt.style.use(['science'])
# plt.style.use(['science','ieee', 'no-latex'])
# plt.style.use(['science','nature'])
# plt.style.use(['science','bright', 'no-latex'])
# plt.style.use(['science','vibrant', 'no-latex'])
# plt.style.use(['science','muted', 'no-latex'])
# plt.style.use(['science','high-contrast','grid'])
# plt.style.use(['science','ieee','light','grid'])
plt.rc('font', family='Times New Roman') 


import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Z = np.array([[90.108,89.245,88.374,88.111],
# [87.208,87.097,88.474,88.799],
# [88.715,89.618,88.357,88.799],
# [88.112,89.245,88.374,88.111]])

Z = np.array([[88.835, 87.821, 87.591, 87.948],
[88.601, 88.273, 87.459, 88.350 ],
[89.006, 88.359, 86.988, 88.058],
[90.947, 88.961, 86.467, 88.618]])



def draw_3d_pic(name,Z):
    X = np.array([0.2, 0.4, 0.6, 0.8])
    Y = np.array([0.2, 0.4, 0.6, 0.8])
    X, Y = np.meshgrid(X, Y)
    fig, ax = plt.subplots(subplot_kw={"projection": "3d"},figsize=(10,15))
    # fig.patch.set_alpha(1)
    # norm = matplotlib.colors.Normalize(vmax = 92, clip = False)
    norm = matplotlib.colors.Normalize(clip = False)
    # ax.set_xlabel(r'$\alpha$',size=17)   # here
    # ax.set_ylabel(r'$\beta$',size=17)
    ax.set_zlabel(name,size=18)
    fig.text(0.79, 0.31, r'$\beta$', size=18)
    fig.text(0.35, 0.26, r'$\alpha$', size=18)
    # fig.text(0.883, 0.535, name, size=18)

    ax.set_xticks([0.2, 0.4, 0.6, 0.8])
    ax.set_yticks([0.2, 0.4, 0.6, 0.8])
    
    # ax.set_zticks([np.min(Z)//1+1, np.min(Z)//1 + 3, np.min(Z)//1 + 5])
    ax.set_zticks([86, 88, 90, 92])
    vmin = (8-(np.max(Z) - np.min(Z))) // 2 + 1
    ax.set_zticks([np.min(Z)//1 - vmin + 2, np.min(Z)//1 - vmin + 4, np.min(Z)//1 - vmin + 6, np.min(Z)//1 - vmin + 8, np.min(Z)//1 - vmin + 10])
    # jiange = (np.max(Z)//1 - np.min(Z)//1) // 4 if (np.max(Z)//1 - np.min(Z)//1)%4 == 0 else (np.max(Z)//1 - np.min(Z)//1) // 4 + 1
    # ax.set_zticks([np.min(Z)//1-1, np.min(Z)//1+jiange-1, np.min(Z)//1+jiange*2-1, np.min(Z)//1+jiange*3-1, np.min(Z)//1+jiange*4-1, np.min(Z)//1+jiange*5-1])
    ax.invert_xaxis()

    ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
    ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
    ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
    
    ax.tick_params(labelsize=17)
    ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([1.1, 1, 1, 1]))
    ax.view_init(20, -60)
    
    ax.plot_surface(X, Y, Z, cmap="cool",norm=norm, edgecolors='k', lw=0.8)
    ax.set_xlim(0.8, 0.2)
    ax.set_ylim(0.2, 0.8)
    ax.set_zlim(np.min(Z)//1 - vmin,np.min(Z)//1 - vmin + 10)
    # ax.set_zlim(np.min(Z)//1, np.max(Z)//1+1)
    # ax.set_zlim(np.min(Z)//1-1,np.min(Z)//1+jiange*5-1)

    ax.patch.set_facecolor('white')

    # plt.axis([0.2, 0.8, 0.8, 0.2])
    
    plt.savefig("/home/hlf/code/draw_figure/draw_figure/HHGSI//{}.png".format(name), dpi=300,format="png")
# plt.show()

Z = np.array([[88.835, 87.821, 87.591, 87.948],
[88.601, 88.273, 87.459, 88.350 ],
[89.006, 88.359, 86.988, 88.058],
[90.947, 88.961, 86.467, 88.618]])
draw_3d_pic('Micro-P',Z)
Z = np.array([[86.577,87.053,86.338,85.782],
[87.053,87.291,85.306,86.736],
[87.450,86.815,86.021,86.100],
[86.180,87.053,84.750,86.577]])
draw_3d_pic('Micro-R', Z)
Z = np.array([[87.691,87.435,86.96,86.852],
[87.821,87.78,86.369,87.535],
[88.221,87.58,86.502,87.068],
[88.499,87.997,85.600 ,87.585]])
draw_3d_pic('Micro-F1', Z)
Z = np.array([[84.33,82.377,81.786,80.153],
[87.467,85.427,82.398,82.785],
[86.473,83.161,83.314,81.536],
[87.639,83.047,81.059,83.743]])
draw_3d_pic('Macro-P', Z)
Z = np.array([[78.279,82.104,79.778,78.057],
[80.814,81.752,79.963,78.913],
[79.570,79.815,77.600,79.409],
[79.838,79.982,78.516,81.715]])
draw_3d_pic('Macro-R', Z)
Z = np.array([[80.731,81.996,80.647,78.968],
[83.123,83.390,80.880,80.236],
[82.037,81.300,80.000,80.289],
[83.295,81.411,79.596,82.656]])
draw_3d_pic('Macro-F1', Z)
Z = np.array([[83.839,83.313,83.074,82.661],
[83.879,83.205,82.424,83.377],
[84.369,83.488,82.119,82.992],
[84.130,83.972,81.108,83.611]])
draw_3d_pic('mAP', Z)


























